package top.kaoshanji.p2ch14a;

import top.kaoshanji.u1constant.FileConstant;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Random;

/**
 * 代码清单-p2ch14a-405页c：BasicQueue的消费者
 * author kaoshanji
 * ^_^
 * create time 2025/2/22 18:17
 */
public class BasicQueueConsumer {

    public static void main(String[] args) throws IOException, InterruptedException {

        BasicQueue queue = new BasicQueue(FileConstant.BASIC_QUEUE_ROOT_PATH, "task");
        Random rnd = new Random();
        while (true) {
            byte[] bytes = queue.dequeue();
            if (bytes == null) {
                Thread.sleep(rnd.nextInt());
                continue;
            }

            System.out.println("consume: " + new String(bytes, StandardCharsets.UTF_8));
        }
    }

}
